<template>
  <div>
    <ComDialog
      title="修改定价"
      :dialogVisible="dialogVisible"
      @EventClose="closeFn"
    >
      <el-form
        :model="editForm"
        :rules="rules"
        ref="editForm"
        label-width="100px"
        class="demo-editForm"
      >
        <template v-if="isImgText">
          <el-form-item :label="category"></el-form-item>
        </template>
        <template v-else>
          <el-form-item label="专家等级" prop="level">
            <el-select v-model="editForm.level">
              <el-option
                v-for="(item, index) in levelOptions"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </template>

        <template> </template>
        <el-form-item :label="priceType" prop="price">
          <el-input v-model.number="editForm.price"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio v-model="editForm.status" label="0">正常</el-radio>
          <el-radio v-model="editForm.status" label="1">停用</el-radio>
        </el-form-item>

        <el-form-item>
          <el-button @click="closeFn">取消</el-button>
          <el-button type="primary" @click="saveFn">保存</el-button>
        </el-form-item>
      </el-form>
    </ComDialog>
  </div>
</template>
<script>
import ComDialog from "../../../../components/comDialog.vue";
import {
  getPriceConsultGetInfoApi,
  getPriceConsultEditApi,
} from "@/wss/api/financial/pricing/priceConsult.js";
import { getCareerListApi } from "@/wss/api/HumanResources/career.js";
export default {
  props: {
    isImgText: {
      type: Boolean,
      default: false,
    },
    //  价格类型
    priceType: {
      type: String,
      default: "出错",
    },
    // 是否显示对话框
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  components: { ComDialog },
  data() {
    return {
      // 类目
      category: "",
      // 职等数组
      levelOptions: [],
      editForm: {
        type: "",
        level: "",
        priceType: "",
        price: 0,
        status: "",
      },
      rules: {
        price: [
          {
            required: true,
            type: "number",
            message: "无效",
            trigger: "blur",
          },
        ],
        status: [{ required: true, message: "请选择状态", trigger: "change" }],
        level: [{ required: true, message: "请选择等级", trigger: "change" }],
      },
    };
  },
  created() {
    this.getLevelListFn();
  },
  methods: {
    // 获取职位列表
    async getLevelListFn() {
      let { rows, code } = await getCareerListApi();

      if (code == 200) {
        rows.forEach((item) => {
          this.levelOptions.push({
            label: item.level,
            value: item.idStr,
          });
        });
        console.log(this.levelOptions, "返回的数据");
      }
    },
    // 获取详细
    async getDetailFn(row) {
      let { data, code } = await getPriceConsultGetInfoApi({
        id: row.idStr,
      });
      if (code === 200) {
        console.log(data);
        data.category == 1
          ? (this.category = "合同代拟")
          : (this.category = "合同审核");
        this.editForm = data;
        // 转换为字符串
        this.editForm.level = this.editForm.levelStr.toString();
      }
    },
    // 修改的保存 按钮
    async saveFn() {
      this.editForm.id = this.editForm.idStr;

      let { code, msg } = await getPriceConsultEditApi(this.editForm);
      console.log(msg, "返回的结果");
      if (code == 200) {
        this.$emit("update:dialogVisible", false).$emit("EventGetList");
        this.$modal.msgSuccess(msg);
      }
    },
    // 关闭对话框
    async closeFn() {
      // 关闭对话框 =>  重新获取列表数据 $emit返回该组件实例
      this.$emit("update:dialogVisible", false);
    },
  },
};
</script>